package cn.qiyu5522.controller;

import cn.qiyu5522.domain.entity.ResponseResult;
import cn.qiyu5522.domain.entity.SystemException;
import cn.qiyu5522.domain.entity.User;
import cn.qiyu5522.enums.AppHttpCodeEnum;
import cn.qiyu5522.service.LoginService;
import cn.qiyu5522.service.MenuService;
import cn.qiyu5522.service.RoleService;
import cn.qiyu5522.service.UserService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * ClassName: LoginController
 * Package: cn.qiyu5522.controller
 * Description:
 *
 * @Author: Tonkey
 * @Create：2024/4/17-8:34
 * @Version: v1.0
 */

@RestController
public class LoginController {

    @Resource
    private LoginService loginService;

    @Resource
    private UserService userService;

    @Resource
    private RoleService roleService;

    @Resource
    private MenuService menuService;


    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody User user){
        if(!StringUtils.hasText(user.getUserName())){
            //提示 必须要传用户名
            throw new SystemException(AppHttpCodeEnum.REQUIRE_USERNAME);
        }
        return loginService.login(user);
    }


    @GetMapping("/getInfo")
    public ResponseResult getInfo(){
        return  loginService.getInfo();
    }

    @GetMapping("/getRouters")
    public ResponseResult getRouters(){
        return loginService.getRouters();
    }

    @PostMapping("/user/logout")
    public ResponseResult logout(){
        return loginService.logout();
    }
}
